﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Mvc;
using KM.BUS;
using KM.ENT;
using KM.Models;
using System.Linq;

namespace KM.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            //busLoaiKhuyenMai busLKM = new busLoaiKhuyenMai();
            //List<entLoaiKhuyenMai> lst2 = new List<entLoaiKhuyenMai>();
            //lst2 = busLKM.getAll();
            //ViewBag.lstLKM = lst2;

            //List<Users> lst = new List<Users>();
            //lst.Add(new Users() { UserId = "1", UserName="Name1" });
            //lst.Add(new Users() { UserId = "2", UserName = "Name2" });
            //lst.Add(new Users() { UserId = "3", UserName = "Name3" });
            //ViewBag.me = lst.Count.ToString();
            return View(new Users { UserId = "2", UserName = "name" });
        }
        [HttpPost]
        public ActionResult Index(Users user)
        {
            busLoaiKhuyenMai busLKM = new busLoaiKhuyenMai();
            List<entLoaiKhuyenMai> lst2 = new List<entLoaiKhuyenMai>();
            lst2 = busLKM.getAll();
            ViewBag.lstLKM = lst2;

            ViewBag.me = user.UserName;
            return View(new Users { UserId="1", UserName="name" });
        }
        //public ActionResult phantrang()
        //{
        //    CustomerModel m = new CustomerModel();

        //    var customerlist = m.GetAllCustomer();
        //    return View();

        //}
        private int pageSize = 5;
        public ActionResult phantrang(int page=1)
        {
            CustomerModel m = new CustomerModel();
            CustomerViewModel vm = new CustomerViewModel
            {
                Customers = m.GetAllCustomer().Skip((page - 1) * pageSize).Take(pageSize),
                PagingInfoModel = new PagingInfoModel
                {
                    CurrentPage = page,
                    recordPerPage = pageSize,
                    totalRecords = m.GetAllCustomer().Count()
                }
            };
            return View(vm);
        }

    }
}
